package com.wmm.servlet.classes;

import com.wmm.bean.Classes;
import com.wmm.service.ClassesService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "UpdateClassServlet", urlPatterns = "/updateClass")
public class UpdateClassServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        String classNo = request.getParameter("classNo");
        String className = request.getParameter("className");
        ClassesService classService = new ClassesService();
        List<Classes> query = classService.queryClassesServer(classNo, className);
        HttpSession session = request.getSession();
        session.setAttribute("updateClass",query.get(0));
        session.setAttribute("classname",className);
        session.setAttribute("classNo",classNo);
        response.sendRedirect("updateClass.jsp");

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
